<?php
class daoshi extends CI_Controller {
	function index() {
		$this -> pub -> logp('导师管理', '2', 'plug_voice');
		$da = $this -> pub -> get_setting('导师', 'DAOSHI');
		$this -> load -> view('adminx/daoshi', $da);
	}

	function add() {
		$this -> pub -> logp('创建导师', '1-2');
		$da['name'] = $this -> input -> post('name');
		$da['tx'] = $this -> input -> post('tx');
		$da['sy'] = $this -> input -> post('sy');
		$da['jj'] = $this -> input -> post('jj');
		$da['geyan'] = $this -> input -> post('geyan');
		$da['state'] = $this -> input -> post('state');
		$da['url'] = $this -> input -> post('url');
		$da['sort'] = $this -> input -> post('sort');
		$da['mktime'] = mktime();
		$this -> db -> insert('sp_daoshi', $da);
		echo json_encode(array('type' => 1));
	}

	function up() {
		$this -> pub -> logp('导师修改 - ' . $this -> input -> post('idx'), '1-2');
		$da['name'] = $this -> input -> post('name');
		if ($this -> input -> post('tx')) {
			$da['tx'] = $this -> input -> post('tx');
		}
		$da['sy'] = $this -> input -> post('sy');
		$da['jj'] = $this -> input -> post('jj');
		$da['geyan'] = $this -> input -> post('geyan');
		$da['state'] = $this -> input -> post('state');
		$da['url'] = $this -> input -> post('url');
		$da['sort'] = $this -> input -> post('sort');
		$this -> db -> update('sp_daoshi', $da, array('id' => $this -> input -> post('idx')));
		echo json_encode(array('type' => 1));
	}

	function get_one() {
		$this -> pub -> logp('获取导师信息 - ' . $this -> input -> post('idx'), '1-2');
		$q = $this -> db -> get_where('sp_daoshi', array('id' => $this -> input -> post('idx')));
		if ($q -> num_rows() > 0) {
			$da = $q -> row_array(0);
			$da['typex'] = 1;
			echo json_encode($da);
		} else {
			echo json_encode(array('typex' => 2));
		}
	}

	function get() {
		$this -> pub -> logp('获取导师信息', '1-2');
		if ($this -> input -> post('key')) {
			$this -> db -> like('name', $this -> input -> post('key'));
		}
		$q = $this -> db -> get_where('sp_daoshi');
		$state[1] = '上架';
		$state[2] = '下架';
		$sy[1] = '是';
		$sy[2] = '否';
		$da['content'] = '';
		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['id'] . '</td>';
			$da['content'] .= '<td><img width="80" src="' . $this -> pub -> oss_dz($v['tx']) . '" /></td>';
			$da['content'] .= '<td>' . $v['name'] . '</td>';
			$da['content'] .= '<td>' . $state[$v['state']] . '</td>';
			$da['content'] .= '<td>' . $sy[$v['sy']] . '</td>';
			$da['content'] .= '<td><button onclick="show_up(\'' . $v['id'] . '\')" type="button"  class="btn default"><i class="fa fa-edit"></i>修改</button>  </td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>